<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use kartik\daterange\DateRangePicker;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel app\models\ProjectCommentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', '评论管理');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="project-comment-index box box-primary">
    <?php Pjax::begin(); ?>

    <div class="box-body table-responsive no-padding">
        <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'layout' => "{items}\n{summary}\n{pager}",
            'emptyText' =>'没有符合条件的数据!',
            'columns' => [
                // ['class' => 'yii\grid\SerialColumn'],

                'id',
                'project_id',
                [
                    'attribute' => 'username',
                ],
                'content:html',
                'star',
                // 'picture:ntext',
                [    
                    'options' => ['width' => '110px'],
                    'attribute' => 'is_top',
                    'format' => 'html',
                    'value'=>function($model) use ($searchModel){
                        return $searchModel::getSetHotStatus($model['is_top']);
                    },
                    'filter' => $searchModel::getSetHotStatus(),     //此处我们可以将筛选项组合成key-value形式
                ],
                [    
                    'options' => ['width' => '110px'],
                    'attribute' => 'is_read_by_self',
                    'format' => 'html',
                    'value'=>function($model) use ($searchModel){
                        return $searchModel::getSelfSeeStatus($model['is_read_by_self']);
                    },
                    'filter' => $searchModel::getSelfSeeStatus(),     //此处我们可以将筛选项组合成key-value形式
                ],
                //创建时间
                [
                    'attribute'          => 'created_time',
                    'format' => ['date', "php:Y-m-d H:i:s"],
                    'headerOptions' => ['width' => '12%'],
                    'filter' => DateRangePicker::widget([
                        'name' => $searchModel->formName().'[created_time]',
                        'language'=>'zh-cn', 
                        'value' => Yii::$app->request->get($searchModel->formName())['created_time'],
                        'convertFormat' => true,
                        'pluginOptions' => [
                            'timePicker'=>true,
                            'timePickerIncrement'=>30,
                            'locale'=>['format'=>'Y-m-d H:i:s'],
                            'ranges' => [
                                Yii::t('app', "Today") => ["moment().startOf('day')", "moment()"],
                                Yii::t('app', "Yesterday") => ["moment().startOf('day').subtract(1,'days')", "moment().endOf('day').subtract(1,'days')"],
                                Yii::t('app', "Last {n} Days", ['n' => 7]) => ["moment().startOf('day').subtract(6, 'days')", "moment()"],
                                Yii::t('app', "Last {n} Days", ['n' => 30]) => ["moment().startOf('day').subtract(29, 'days')", "moment()"],
                                Yii::t('app', "This Month") => ["moment().startOf('month')", "moment().endOf('month')"],
                                Yii::t('app', "Last Month") => ["moment().subtract(1, 'month').startOf('month')", "moment().subtract(1, 'month').endOf('month')"],
                            ],
                        ]
                    ]),  
                ],
                // 'updated_time:datetime',
                //操作按钮
                [
                    'options' => ['width' => '135px'],
                    'filter'  => Html::a(Yii::t('app', '重置'), Url::to(['']), ['class' => 'btn btn-info', 'style' => 'color: #ffffff;']),
                    'format'  => 'raw',
                    'label'   => Yii::t('app', '操作'),
                    'value'   => function ($model) {
                        $actionDom = '';
                        $actionDom .= Html::a(
                            \Yii::t('app', '详情'),
                            Url::to(['view', 'id' => $model['id']]),
                            [
                                'data'  => [
                                    'pjax' => 0,
                                ],
                                'class' => 'btn btn-info btn-xs'
                            ]
                        );

                        $lable = $model->is_top == 1 ? \Yii::t('app', '取消置顶') : \Yii::t('app', '置顶');
                        $actionDom .= Html::a(
                            $lable,
                            Url::to(['set-top', 'id' => $model['id'], 'is_top' => $model->is_top == 1? 0 : 1]),
                            [
                                'data'  => [
                                    'pjax' => 0,
                                    'confirm' => '确定要'.$lable.'?',
                                ],
                                'class' => 'btn btn-warning btn-xs'
                            ]
                        );

                        $lable = $model->is_read_by_self == 1 ? \Yii::t('app', '所有人可见') : \Yii::t('app', '仅自己可见');
                        $actionDom .= Html::a(
                            $lable,
                            Url::to(['make-see', 'id' => $model['id'], 'is_read_by_self' => $model->is_read_by_self == 1? 0 : 1]),
                            [
                                'data'  => [
                                    'pjax' => 0,
                                    'confirm' => '确定要'.$lable.'?',
                                ],
                                'class' => 'btn btn-danger btn-xs'
                            ]
                        );
                        return Html::tag('div', $actionDom, ['class' => 'btn-group-vertica']);
                    },
                ],
                


            ],
        ]); ?>
    </div>
    <?php Pjax::end(); ?>
</div>
